package com.zahb.qadx.ui.activity.topic;

import android.content.Intent;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.githang.statusbar.StatusBarCompat;
import com.luck.picture.lib.tools.ToastUtils;
import com.zahb.qadx.R;
import com.zahb.qadx.base.BaseActivity;
import com.zahb.qadx.model.AnswerSheetListBean;
import com.zahb.qadx.model.ExamQuestionsBean;
import com.zahb.qadx.model.ResultsBean;
import com.zahb.qadx.model.UserAnswerBean;
import com.zahb.qadx.net.RetrofitService;
import com.zahb.qadx.ui.view.MyDialog;
import com.zahb.qadx.util.Constant;
import com.zahb.qadx.util.Tips;

import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;

//考试解析
public class TestQuestionParsingActivity extends BaseActivity {

    @BindView(R.id.current_qid)
    TextView currentQid;
    @BindView(R.id.the_topic_order)
    TextView theTopicOrder;
    @BindView(R.id.first_layout)
    LinearLayout firstLayout;
    @BindView(R.id.test_list_recyclerView)
    RecyclerView mRecyclerView;
    @BindView(R.id.sheet)
    TextView sheet;
    @BindView(R.id.on_a_topic)
    TextView onATopic;
    @BindView(R.id.next_question)
    TextView nextQuestion;
    private String examUserResultId, type, limitCheck, questionType;

    private ExamQuestionsBean mExamQuestionsBean;
    private MultipleItemAdapter mAdapter;
    private List<MyMultipleItem> mDatas02;
    public LinearLayoutManager mLayoutManager;
    private String[] serialNumber = {"A", "B", "C", "D", "E", "F", "G", "H"};
    private String[] theSerialNumber = {"(1) . ", "(2) . ", "(3) . ", "(4) . ", "(5) . ", "(6) . ", "(7) . ", "(8) . ", "(9) . ", "(10) . "};
    private BaseQuickAdapter<UserAnswerBean, BaseViewHolder> mmAdapter;
    // 答题卡
    private MyDialog mMyDialog;
    public RecyclerView answer_sheetr_ecyclerView;
    private BaseSectionQuickAdapter<AnswerSheetListBean, BaseViewHolder> mSheetAdapter;
    private List<AnswerSheetListBean> mExercisesWeeklies;
    private AnswerSheetListBean mExercisesWeekly;
    private int count = 0;
    private int countS = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mUnbinder = ButterKnife.bind(this);
        navigationInitialization();//导航栏初始化

    }

    @Override
    protected int getLayout() {
        return R.layout.activity_test_question_parsing;
    }

    @Override
    protected void initViews() {
        examUserResultId = getIntent().getStringExtra("examUserResultId");
        type = getIntent().getStringExtra("type");
        limitCheck = getIntent().getStringExtra("limitCheck");
        questionType = getIntent().getStringExtra("questionType");
        results();
    }

    private void results() {
        addDisposable(RetrofitService.getNetService()
                .getTestQuestionParsing(examUserResultId, type, limitCheck, questionType)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(response -> {
                    if (response.getStatusCode() == Constant.CODE_SUCCESS) {
                        mExamQuestionsBean = response.getData();
                        if (mExamQuestionsBean.getClassIfyList().size() == 1) {
                            nextQuestion.setText("结束");
                        } else {
                            nextQuestion.setText("下一题");
                        }
                        mDatas02 = new ArrayList<>();
                        //这里我是随机给某一条目加载不同的布局
                        for (int i = 0; i < mExamQuestionsBean.getClassIfyList().size(); i++) {
                            if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 1) {//单选
                                for (int j = 0; j < mExamQuestionsBean.getClassIfyList().get(i).getQuesList().size(); j++) {
                                    mDatas02.add(new MyMultipleItem(MyMultipleItem.FIRST_TYPE, mExamQuestionsBean.getClassIfyList().get(i).getQuesList().get(j)));
                                }
                            } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 2) {//多选
                                for (int a = 0; a < mExamQuestionsBean.getClassIfyList().get(i).getQuesList().size(); a++) {
                                    mDatas02.add(new MyMultipleItem(MyMultipleItem.SECOND_TYPE, mExamQuestionsBean.getClassIfyList().get(i).getQuesList().get(a)));
                                }
                            } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 3) {//判断
                                for (int a = 0; a < mExamQuestionsBean.getClassIfyList().get(i).getQuesList().size(); a++) {
                                    mDatas02.add(new MyMultipleItem(MyMultipleItem.NORMAL_TYPE, mExamQuestionsBean.getClassIfyList().get(i).getQuesList().get(a)));
                                }
                            } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 4) {//填空
                                for (int a = 0; a < mExamQuestionsBean.getClassIfyList().get(i).getQuesList().size(); a++) {
                                    mDatas02.add(new MyMultipleItem(MyMultipleItem.EMPTY_FOUR, mExamQuestionsBean.getClassIfyList().get(i).getQuesList().get(a)));
                                }
                            } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 5) {//简答
                                for (int a = 0; a < mExamQuestionsBean.getClassIfyList().get(i).getQuesList().size(); a++) {
                                    mDatas02.add(new MyMultipleItem(MyMultipleItem.JANE_FIVE, mExamQuestionsBean.getClassIfyList().get(i).getQuesList().get(a)));
                                }
                            } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 6) {//案例
//                                mDatas02.add(new MyMultipleItem(MyMultipleItem.NORMAL_TYPE, mDailyExaminationQuestionsBean.get(i)));
                            }
                        }
                        //创建布局管理
                        mLayoutManager = new LinearLayoutManager(this);
                        mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                        mRecyclerView.setLayoutManager(mLayoutManager);
                        //创建适配器
                        mAdapter = new MultipleItemAdapter(mDatas02);
                        //给RecyclerView设置适配器
                        mRecyclerView.setAdapter(mAdapter);
                        PagerSnapHelper snapHelper = new PagerSnapHelper();
                        //加在setAdapter后面
                        snapHelper.attachToRecyclerView(mRecyclerView);
                        int count = 0;
                        for (int i = 0; i < mExamQuestionsBean.getClassIfyList().size(); i++) {
                            count = count + mExamQuestionsBean.getClassIfyList().get(i).getQuesList().size();
                        }
                        countS=count;
                        theTopicOrder.setText("/" + count + "   " + testingTypes(mExamQuestionsBean.getClassIfyList().get(0).getQuestionType()));
                        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                            @Override
                            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                                super.onScrollStateChanged(recyclerView, newState);
                                if (newState == 0&&mLayoutManager.findFirstCompletelyVisibleItemPosition()!=-1) {
                                    controlTheAnswer(countS,mLayoutManager.findFirstCompletelyVisibleItemPosition() + 1);

                                }
                            }
                        });
                    } else {

                    }
                }, throwable -> {
                    throwable.printStackTrace();
                    Tips.RequestError(getActivity());
                }));

    }

    //答题卡
    private void answerSheetList() {
        count = 0;
        View view = getLayoutInflater().inflate(R.layout.answer_sheet_layout, null);
        mMyDialog = new MyDialog(getActivity(), 0, 0, view, R.style.dialog);
        TextView answer_cancel = view.findViewById(R.id.answer_cancel);
        answer_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mMyDialog.dismiss();
            }
        });
        answer_sheetr_ecyclerView = view.findViewById(R.id.answer_sheetr_ecyclerView);
        answer_sheetr_ecyclerView.setLayoutManager(new GridLayoutManager(this, 5));
        answer_sheetr_ecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
                outRect.set(0, 0, 0, 0);
            }
        });

        mExercisesWeeklies = new ArrayList<>();
        //这里我是随机给某一条目加载不同的布局

        for (int i = 0; i < mExamQuestionsBean.getClassIfyList().size(); i++) {
            if (mExamQuestionsBean.getClassIfyList().get(i).getQuesList().size() != 0) {
                if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 1) {
                    sortTheAnswerSheets("单选题", i);
                } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 2) {
                    sortTheAnswerSheets("多选题", i);
                } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 3) {
                    sortTheAnswerSheets("判断题", i);
                } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 4) {
                    sortTheAnswerSheets("填空题", i);
                } else if (mExamQuestionsBean.getClassIfyList().get(i).getQuestionType() == 5) {
                    sortTheAnswerSheets("简答题", i);
                }
            }

        }
        mSheetAdapter = new BaseSectionQuickAdapter<AnswerSheetListBean, BaseViewHolder>(
                R.layout.grouping_layout, R.layout.team_members_layout, mExercisesWeeklies) {
            @Override
            protected void convertHeader(@NotNull BaseViewHolder baseViewHolder, @NotNull AnswerSheetListBean item) {
                TextView text_header = baseViewHolder.findView(R.id.text_header);
                text_header.setText(item.getTitle());
            }

            @Override
            protected void convert(@NotNull BaseViewHolder baseViewHolder, AnswerSheetListBean item) {
                TextView tvName = baseViewHolder.getView(R.id.text_content);
                tvName.setText(item.getQid() + "");
                tvName.setTextColor(getResources().getColor(R.color.white_ffffff));
                if (item.getTheAnswerState() == 0) {
                    tvName.setBackground(getContext().getResources().getDrawable(R.drawable.the_green_circle));
                } else if (item.getTheAnswerState() == 1) {
                    tvName.setBackground(getContext().getResources().getDrawable(R.drawable.the_red_circle_360dp));

                } else {
                    tvName.setBackground(getContext().getResources().getDrawable(R.drawable.grey_circle_360dp));

                }

                tvName.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        controlTheAnswer(mDatas02.size(), item.getQid());
                        mMyDialog.dismiss();
                    }
                });

            }
        };
//        mSheetAdapter.setOnItemChildClickListener(this);
        mSheetAdapter.addChildClickViewIds(R.id.text_content);
        answer_sheetr_ecyclerView.setAdapter(mSheetAdapter);

    }

    //答题卡排序
    private void sortTheAnswerSheets(String type, int i) {
        mExercisesWeekly = new AnswerSheetListBean();
        mExercisesWeekly.setGrouping(0);
        mExercisesWeekly.setTitle(type);
        mExercisesWeeklies.add(mExercisesWeekly);
        for (int j = 0; j < mExamQuestionsBean.getClassIfyList().get(i).getQuesList().size(); j++) {
            count++;
            mExercisesWeekly = new AnswerSheetListBean();
            mExercisesWeekly.setQid(count);
            mExercisesWeekly.setGrouping(1);
            if (mExamQuestionsBean.getClassIfyList().get(i).getQuesList().get(j).getWrongFlag() == 1) {

                if (mExamQuestionsBean.getClassIfyList().get(i).getQuesList().get(j).getUserAnswer().size() == 0) {
                    mExercisesWeekly.setTheAnswerState(2);
                } else {
                    mExercisesWeekly.setTheAnswerState(1);
                }
            } else {
                mExercisesWeekly.setTheAnswerState(0);
            }
            mExercisesWeeklies.add(mExercisesWeekly);
        }

    }


    //控制选题
    private void controlTheAnswer(int allAnswer, int current) {

        currentQid.setText(current + "");
        if (current == allAnswer) {
            nextQuestion.setText("结束");
        } else {
            nextQuestion.setText("下一题");
        }

        if (mLayoutManager.findFirstCompletelyVisibleItemPosition() - current > 5 || current - mLayoutManager.findFirstCompletelyVisibleItemPosition() > 5) {
            mRecyclerView.scrollToPosition(current - 1);
            ExamQuestionsBean.ClassIfyListBean.QuesListBean quesListBean= (ExamQuestionsBean.ClassIfyListBean.QuesListBean) mDatas02.get(current-1).getData();
            theTopicOrder.setText("/" +allAnswer+"   " +testingTypes(quesListBean.getQuestionType()));
        } else {
            mRecyclerView.smoothScrollToPosition(current - 1);
            ExamQuestionsBean.ClassIfyListBean.QuesListBean quesListBean= (ExamQuestionsBean.ClassIfyListBean.QuesListBean) mDatas02.get(current-1).getData();
            theTopicOrder.setText("/" +allAnswer+"   " +testingTypes(quesListBean.getQuestionType()));

        }
    }
    private String testingTypes(int questionType) {
        switch (questionType) {
            case 1:
                return "单选题";
            case 2:
                return "多选题";
            case 3:
                return "判断题";
            case 4:
                return "填空题";
            case 5:
                return "简答题";
            case 6:
                return "案例题";

        }


        return "试题";
    }

    @OnClick({R.id.on_a_topic, R.id.next_question, R.id.sheet})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.on_a_topic://上一题
                if (mExamQuestionsBean==null){
                    return;
                }
                if (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) {
                    ToastUtils.s(this, "当前是第一道题");
                } else {
                    if (mLayoutManager.findLastCompletelyVisibleItemPosition() == -1) return;
                    controlTheAnswer(mDatas02.size(), mLayoutManager.findFirstCompletelyVisibleItemPosition());


                }
                break;
            case R.id.next_question://下一题
                if (mExamQuestionsBean==null){
                    return;
                }
                if (mLayoutManager.findFirstCompletelyVisibleItemPosition() == (mDatas02.size() - 1)) {

                    finish();
                } else {
                    if (mLayoutManager.findLastCompletelyVisibleItemPosition() == -1) return;
                    controlTheAnswer(mDatas02.size(), mLayoutManager.findFirstCompletelyVisibleItemPosition() + 2);
                }
                break;
            case R.id.sheet:
                if (mExamQuestionsBean==null){
                    return;
                }
                answerSheetList();//答题卡
                mMyDialog.show_widescreen();
                answer_sheetr_ecyclerView.scrollToPosition(mLayoutManager.findFirstCompletelyVisibleItemPosition());
                break;
        }
    }

    @Override
    protected int getTitleStringRes() {
        return R.string.test_question_parsing;
    }

    private void navigationInitialization() {
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.blue));//状态栏颜色
        mTopBarContainer.setBackgroundColor(getResources().getColor(R.color.blue));//头部布局颜色
        mTitle_view.setTextColor(getResources().getColor(R.color.white));//标题颜色
        Drawable drawable = getResources().getDrawable(R.mipmap.fanhui);//返回箭头
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());// 设置边界
        // param 左上右下
        mTopBarStartText.setCompoundDrawables(drawable, null, null, null);
        mTopBarStartText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    public class MultipleItemAdapter extends BaseMultiItemQuickAdapter<MyMultipleItem, BaseViewHolder> {
        public MultipleItemAdapter(List data) {
            super(data);
            //必须绑定type和layout的关系
            addItemType(MyMultipleItem.FIRST_TYPE, R.layout.the_radio);
            addItemType(MyMultipleItem.SECOND_TYPE, R.layout.multi_elect);
            addItemType(MyMultipleItem.NORMAL_TYPE, R.layout.the_radio);
            addItemType(MyMultipleItem.EMPTY_FOUR, R.layout.filiintheblanks_layout);
            addItemType(MyMultipleItem.JANE_FIVE, R.layout.short_answer_layout);
        }

        @Override
        protected void convert(final BaseViewHolder helper, final MyMultipleItem item) {

            switch (helper.getItemViewType()) {
                case MyMultipleItem.FIRST_TYPE://d单选题
                    theRadio(helper, item);
                    break;
                case MyMultipleItem.SECOND_TYPE://多选题
                    multiSelect(helper, item);
                    break;
                case MyMultipleItem.NORMAL_TYPE:
                    theRadio(helper, item);
                    break;
                case MyMultipleItem.EMPTY_FOUR://填空
                    fillInTheBlanks(helper, item);
                    break;
                case MyMultipleItem.JANE_FIVE://简答
                    shortAnswer(helper, item);
                    break;
            }

        }

        //单选
        private void theRadio(BaseViewHolder helper, MyMultipleItem<ExamQuestionsBean.ClassIfyListBean.QuesListBean> item ) {
            WebView topic_of_dry = helper.findView(R.id.topic_of_dry);//题干
            jsSupport(topic_of_dry, item.getData().getContent());
            TextView answer = helper.findView(R.id.answer);//选择答案
            LinearLayout the_analysis_of = helper.findView(R.id.the_analysis_of);//解析答案布局
            TextView check_the_parsing = helper.findView(R.id.check_the_parsing);

            check_the_parsing.setVisibility(View.GONE);
            the_analysis_of.setVisibility(View.VISIBLE);
            TextView correct_answer = helper.findView(R.id.correct_answer);//正确答案
            TextView parsing = helper.findView(R.id.parsing);
            parsing.setText("本题解析:" + Html.fromHtml(item.getData().getParsing()).toString().trim());
            if (item.getData().getWrongFlag() == 1) {
                answer.setTextColor(getResources().getColor(R.color.red_ff4500));
            } else {
                answer.setTextColor(getResources().getColor(R.color.blue));
            }


            RecyclerView recyclerView = helper.findView(R.id.answer_list);//选择列表
            recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            mmAdapter = new BaseQuickAdapter<UserAnswerBean, BaseViewHolder>(R.layout.choose) {
                @Override
                protected void convert(@NotNull BaseViewHolder baseViewHolder, UserAnswerBean questionOptionListBean) {
                    TextView topic_selection = baseViewHolder.findView(R.id.topic_selection);
                    ImageView selected = baseViewHolder.findView(R.id.selected);
                    TextView the_order = baseViewHolder.findView(R.id.the_order);
                    final LinearLayout linearLayout = baseViewHolder.findView(R.id.the_whole_article);
                    topic_selection.setText(Html.fromHtml(questionOptionListBean.getContent()).toString().trim());
                    the_order.setText(serialNumber[baseViewHolder.getAdapterPosition()]);//顺序ABCD
                    if (questionOptionListBean.getIsRightAnswer().equals("1")) {
                        correct_answer.setText(serialNumber[baseViewHolder.getAdapterPosition()]);
                    }
                    if (item.getData().getUserAnswer().size() != 0) {
                        if (item.getData().getUserAnswer().get(0).getId() == questionOptionListBean.getId()) {
                            topic_selection.setTextColor(getResources().getColor(R.color.blue));
                            the_order.setTextColor(getResources().getColor(R.color.blue));
                            linearLayout.setBackground(getContext().getResources().getDrawable(R.drawable.asingleframe));
                            selected.setVisibility(View.VISIBLE);
                            answer.setText(serialNumber[baseViewHolder.getAdapterPosition()]);
                        } else {

                            topic_selection.setTextColor(getResources().getColor(R.color.colorBlack));
                            the_order.setTextColor(getResources().getColor(R.color.colorBlack));
                            linearLayout.setBackground(getContext().getResources().getDrawable(R.drawable.grey_circle));
                            selected.setVisibility(View.INVISIBLE);


                        }
                    }


                }
            };
            mmAdapter.addData(item.getData().getOptionList());
            recyclerView.setAdapter(mmAdapter);
        }


        //多选
        private void multiSelect(BaseViewHolder helper, MyMultipleItem<ExamQuestionsBean.ClassIfyListBean.QuesListBean> item) {
            TextView check_the_parsing = helper.findView(R.id.check_the_parsing);
            check_the_parsing.setVisibility(View.GONE);
            WebView topic_of_dry = helper.findView(R.id.more_topic_of_dry);//题干
            jsSupport(topic_of_dry,  item.getData().getContent());
            RecyclerView recyclerView = helper.findView(R.id.more_answer_list);//选择列表
            TextView more_correct_answer = helper.findView(R.id.more_correct_answer);//参考答案
            TextView parsing = helper.findView(R.id.more_parsing);
            parsing.setText("本题解析:" + Html.fromHtml(item.getData().getParsing()).toString().trim());
            String reference = "";
            String chooseTheAnswer = "";
            for (int i = 0; i < item.getData().getOptionList().size(); i++) {
                if (item.getData().getOptionList().get(i).getIsRightAnswer().equals("1")) {
                    reference = reference + serialNumber[i];
                }
                for (int j = 0; j < item.getData().getUserAnswer().size(); j++) {
                    if (item.getData().getOptionList().get(i).getId() == item.getData().getUserAnswer().get(j).getId()) {

                        chooseTheAnswer = chooseTheAnswer + serialNumber[i];
                        item.getData().getOptionList().get(i).setChoose(1);
                    }
                }
            }
            more_correct_answer.setText(reference);
            TextView more_determine = helper.findView(R.id.more_determine);
            more_determine.setVisibility(View.GONE);
            TextView more_answer = helper.findView(R.id.more_answer);
            LinearLayout more_the_analysis_of = helper.findView(R.id.more_the_analysis_of);
            more_the_analysis_of.setVisibility(View.VISIBLE);
            if (item.getData().getWrongFlag() == 1) {
                more_answer.setTextColor(getResources().getColor(R.color.red_ff4500));
            } else {
                more_answer.setTextColor(getResources().getColor(R.color.blue));
            }
            more_answer.setText(chooseTheAnswer);
            recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            mmAdapter = new BaseQuickAdapter<UserAnswerBean, BaseViewHolder>(R.layout.choose) {
                @Override
                protected void convert(@NotNull BaseViewHolder baseViewHolder, UserAnswerBean more_questionOptionListBean) {
                    TextView topic_selection = baseViewHolder.findView(R.id.topic_selection);//选项内容
                    ImageView selected = baseViewHolder.findView(R.id.selected);//对号
                    TextView the_order = baseViewHolder.findView(R.id.the_order);//序列号
                    topic_selection.setText(Html.fromHtml(more_questionOptionListBean.getContent()).toString().trim());
                    final LinearLayout linearLayout = baseViewHolder.findView(R.id.the_whole_article);
                    the_order.setText(serialNumber[baseViewHolder.getAdapterPosition()]);//顺序ABCD
                    switch (more_questionOptionListBean.getChoose()) {
                        case 0:
                            topic_selection.setTextColor(getResources().getColor(R.color.colorBlack));
                            the_order.setTextColor(getResources().getColor(R.color.colorBlack));
                            linearLayout.setBackground(getContext().getResources().getDrawable(R.drawable.grey_circle));
                            selected.setVisibility(View.INVISIBLE);

                            break;
                        case 1:
                            topic_selection.setTextColor(getResources().getColor(R.color.blue));
                            the_order.setTextColor(getResources().getColor(R.color.blue));
                            linearLayout.setBackground(getContext().getResources().getDrawable(R.drawable.asingleframe));
                            selected.setVisibility(View.VISIBLE);

                            break;

                    }

                }
            };
            mmAdapter.addData(item.getData().getOptionList());
            recyclerView.setAdapter(mmAdapter);
        }
    }


    //填空
    private void fillInTheBlanks(BaseViewHolder helper, MyMultipleItem<ExamQuestionsBean.ClassIfyListBean.QuesListBean> item) {
        TextView check_the_parsing = helper.findView(R.id.check_the_parsing);
        check_the_parsing.setVisibility(View.GONE);
        WebView empty_topic_of_dry = helper.findView(R.id.empty_topic_of_dry);
        RecyclerView empty_answer_list = helper.findView(R.id.empty_answer_list);
        jsSupport(empty_topic_of_dry,  item.getData().getContent());
        TextView empty_determine = helper.findView(R.id.empty_determine);
        TextView empty_answer = helper.findView(R.id.empty_answer);
        TextView empty_correct_answer = helper.findView(R.id.empty_correct_answer);
        empty_determine.setVisibility(View.GONE);
        LinearLayout empty_the_analysis_of = helper.findView(R.id.empty_the_analysis_of);
        TextView parsing = helper.findView(R.id.parsing);
        parsing.setText("本题解析:" + Html.fromHtml(item.getData().getParsing()).toString().trim());
        empty_the_analysis_of.setVisibility(View.VISIBLE);
        empty_answer_list.setLayoutManager(new LinearLayoutManager(getContext()));
        if (item.getData().getWrongFlag() == 1) {
            empty_answer.setTextColor(getResources().getColor(R.color.red_ff4500));

        } else {
            empty_answer.setTextColor(getResources().getColor(R.color.blue));

        }
        String reference = "";//参考答案
        String chooseTheAnswer = "";//选择答案
        for (int i = 0; i < item.getData().getOptionList().size(); i++) {
            if (item.getData().getOptionList().get(i).getIsRightAnswer().equals("1")) {
                reference = reference + theSerialNumber[i] + item.getData().getOptionList().get(i).getContent();
            }
            for (int j = 0; j < item.getData().getUserAnswer().size(); j++) {
                if (item.getData().getOptionList().get(i).getId() == item.getData().getUserAnswer().get(j).getId()) {
                    chooseTheAnswer = chooseTheAnswer + theSerialNumber[i] + item.getData().getUserAnswer().get(j).getContent();

                }
            }
        }
        empty_correct_answer.setText(reference);
        empty_answer.setText(chooseTheAnswer);
        mmAdapter = new BaseQuickAdapter<UserAnswerBean, BaseViewHolder>(R.layout.fill_in_the_empty_layout) {
            @Override
            protected void convert(@NotNull BaseViewHolder baseViewHolder, UserAnswerBean questionOptionListBean) {
                TextView the_order = baseViewHolder.findView(R.id.the_order);
                EditText topic_selection = baseViewHolder.findView(R.id.topic_selection);
                the_order.setText(theSerialNumber[baseViewHolder.getAdapterPosition()]);
                topic_selection.setText(questionOptionListBean.getContent());
                topic_selection.setFocusable(false);


            }
        };
        mmAdapter.addData(item.getData().getUserAnswer());
        empty_answer_list.setAdapter(mmAdapter);
    }

    //简答
    private void shortAnswer(BaseViewHolder helper, MyMultipleItem<ExamQuestionsBean.ClassIfyListBean.QuesListBean> item) {
        TextView check_the_parsing = helper.findView(R.id.check_the_parsing);
        check_the_parsing.setVisibility(View.GONE);
        WebView short_answer_topic_of_dry = helper.findView(R.id.short_answer_topic_of_dry);
        jsSupport(short_answer_topic_of_dry, item.getData().getContent());
        EditText short_answer_editText = helper.findView(R.id.short_answer_editText);//输入框
        TextView short_answer_determine = helper.findView(R.id.short_answer_determine);
        LinearLayout the_analysis_of = helper.findView(R.id.the_analysis_of);//布局
        TextView parsing = helper.findView(R.id.parsing);
        parsing.setText("本题解析:" + Html.fromHtml(item.getData().getParsing()).toString().trim());
        TextView short_answer_answer = helper.findView(R.id.short_answer_answer);
        TextView short_answer_correct_answer = helper.findView(R.id.short_answer_correct_answer);
        the_analysis_of.setVisibility(View.VISIBLE);
        short_answer_determine.setVisibility(View.GONE);
        if (item.getData().getUserAnswer().size() != 0) {
            short_answer_editText.setText(item.getData().getUserAnswer().get(0).getContent());
            short_answer_answer.setText(item.getData().getUserAnswer().get(0).getContent());
        }
        short_answer_correct_answer.setText(Html.fromHtml(item.getData().getOptionList().get(0).getContent()).toString().trim());
    }

    // WebView 权限
    public void jsSupport(WebView webView, String data) {

        WebSettings webSettings = webView.getSettings();

        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setUseWideViewPort(true);  //将图片调整到适合webview的大小
        webSettings.setTextZoom(270);//设置H5页面中字体大小不跟随手机系统

//        if (Build.VERSION.SDK_INT >= 19) {
//            //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//加载缓存否则网络
//            webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);//不加载缓存
//        }
//
//        if (Build.VERSION.SDK_INT >= 19) {
//            webSettings.setLoadsImagesAutomatically(true);//图片自动缩放 打开
//        } else {
//            webSettings.setLoadsImagesAutomatically(false);//图片自动缩放 关闭
//        }
//
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
//            webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);//软件解码
//        }
//        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);//硬件解码
//
//        webSettings.setJavaScriptEnabled(true); // 设置支持javascript脚本
//        webSettings.setSupportZoom(true);// 设置可以支持缩放
//        webSettings.setBuiltInZoomControls(true);// 设置出现缩放工具 是否使用WebView内置的缩放组件，由浮动在窗口上的缩放控制和手势缩放控制组成，默认false
//
//        webSettings.setDisplayZoomControls(false);//隐藏缩放工具
//        webSettings.setUseWideViewPort(true);// 扩大比例的缩放
//
//        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自适应屏幕
//        webSettings.setLoadWithOverviewMode(true);
//
//        webSettings.setDatabaseEnabled(true);//
//        webSettings.setSavePassword(true);//保存密码
//        webSettings.setDomStorageEnabled(true);//是否开启本地DOM存储  鉴于它的安全特性（任何人都能读取到它，尽管有相应的限制，将敏感数据存储在这里依然不是明智之举），Android 默认是关闭该功能的。
//        webView.setSaveEnabled(true);
//        webView.setKeepScreenOn(true);


        webView.setBackgroundColor(0);
//        ImgStr.getWebview(webView,this,ImgStr.getImgStr(data));
        webView.loadDataWithBaseURL(null,  ImgStr.getImgStr(data), "text/html", "utf-8", null);


    }
}
